<?
 define ('MODEL_QUESTION_ADD',         'INSERT INTO `questions` (`id` ,`author` ,`email` ,`text`, `date`) VALUES (NULL, ?, ?, ?, NOW())');
 
 define ('MODEL_QUESTION_GET_ALL',     'SELECT * FROM `questions` ORDER BY `date` DESC');
 define ('MODEL_QUESTION_GET_ANSWERED','SELECT * FROM `questions` WHERE `state` = 1 ORDER BY `date` DESC');

 define ('MODEL_QUESTION_ADD_ANSWER',  'UPDATE `questions` SET `answer` = ?, state = 1 WHERE `id` = ?'); 
 define ('MODEL_QUESTION_DELETE',      'DELETE FROM `questions` WHERE `id` = ?');

 class Model_Question extends Models_Base {
     
     function add($args) {
         return $this->insertRow(MODEL_QUESTION_ADD,array($args[name],$args[email],$args[text]));
     }
     
     function find($args = null) {
         
         if($args === 'with_answer') 
            return $this->getAll(MODEL_QUESTION_GET_ANSWERED);
         else
            return $this->getAll(MODEL_QUESTION_GET_ALL);
     } 
     
     function add_answer($args) {
         return $this->doExecute(MODEL_QUESTION_ADD_ANSWER,array($args[answer],$args[id]));
     }
     
     function delete($id) {
         return $this->doExecute(MODEL_QUESTION_DELETE,array($id));
     }
     
 }